package com.hqyj.zss.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.zss.dao.EmployeeOrderDao;
import com.hqyj.zss.pojo.Employee;
import com.hqyj.zss.pojo.Order;
import com.hqyj.zss.pojo.PageData;
import com.hqyj.zss.service.EmployeeOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeOrderServiceImpl implements EmployeeOrderService {

    @Autowired
    private EmployeeOrderDao employeeOrderDao;

    //查询所有订单信息
    @Override
    public PageData<Order> queryAllOrder(int pageNumber,int pageSize) {
        //使用PageHelper静态方法，指定页数、每页记录数，此时开始拦截mybatis下一次数据库查询操作
        PageHelper.startPage(pageNumber, pageSize);
        List<Order> userList = employeeOrderDao.queryAllOrder();
        PageInfo<Order> pageInfo = new PageInfo<>(userList);
        PageData<Order> pageData = new PageData<>();
        pageData.setCurrentPage(pageNumber);
        pageData.setPageSize(pageSize);

        if(pageInfo.isHasNextPage()){
            pageData.setNextPage(pageNumber + 1);
        }else{
            pageData.setNextPage(pageNumber);
        }
        if(pageInfo.isHasPreviousPage()){
            pageData.setPreviousPage(pageNumber - 1);
        }else{
            pageData.setPreviousPage(pageNumber);
        }
        pageData.setTotalPage(pageInfo.getPages());
        pageData.setTotalSize((int)pageInfo.getTotal());
        pageData.setList(pageInfo.getList());
        return pageData;
    }

    //取消订单
    @Override
    public int deleteOrder(int o_id) {
        return employeeOrderDao.deleteOrder(o_id);
    }

    @Override
    public Order queryOneOrder(int o_id) {
        return employeeOrderDao.queryOneOrder(o_id);
    }

    //修改订单状态
    @Override
    public int updateOrder(int o_id,int o_state) {
        return employeeOrderDao.updateOrder(o_id,o_state);
    }
    //成本统计
    @Override
    public int orderTotal() {
        return employeeOrderDao.orderTotal();
    }

    @Override
    public int getAllMoney() {

        return employeeOrderDao.getAllMoney();
    }
}
